package com.kgc.controller.admin;

import com.kgc.common.Result;
import com.kgc.entity.User;
import com.kgc.service.interf.admin.AdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author hyj
 * @time 2024/4/3 14:51
 * @describe
 */
@RestController
@RequestMapping("/apis/admin")
public class AdminUserManageController {
    @Autowired
    private AdminService adminService;

    @GetMapping("/getAllUser")
    public String getAllUser() {
        List<User> userList = adminService.getAllUser();
        return Result.success("0", "success", userList);
    }

    @PostMapping("/updateIntegral")
    public String updateIntegral(Integer userId, Integer integral) {
        int i = adminService.updateIntegral(userId, integral);
        if (i == 1) {
            return Result.success("0", "积分修改成功");
        } else {
            return Result.success("1", "积分修改失败");
        }
    }

    @PostMapping("/updateStatus")
    public String updateStatus(Integer userId, Integer status) {
        int i = adminService.updateStatus(userId, status);
        if (i == 1) {
            return Result.success("0", "状态修改成功");
        } else {
            return Result.success("1", "状态修改失败");
        }
    }

    @PostMapping("/cancelUser")
    public String cancelUser(Integer userId) {
        int i = adminService.cancelUser(userId);
        if (i == 1) {
            return Result.success("0", "该用户已成功注销");
        } else {
            return Result.success("1", "该用户注销失败1");
        }
    }
}
